package com.zhiwang.planet.mvvm.viewmodel

import androidx.databinding.ObservableField
import androidx.lifecycle.*
import androidx.paging.PagedList
import com.zhiwang.planet.mvvm.model.entity.main.WithDrawRecord
import com.zhiwang.planet.mvvm.viewmodel.withdraw.DetailRepository
import com.zhiwang.planet.mvvm.viewmodel.withdraw.Listing
import javax.inject.Inject
import javax.inject.Named

class CommonListViewModel @Inject constructor(@Named("user_detail") var detailRepository: DetailRepository) : ViewModel() {


    val emptyHint = ObservableField<Boolean>()

    val refreshing = ObservableField<Boolean>()

    val loadingMore = ObservableField<Boolean>()


    val result  = MutableLiveData(detailRepository.recordsOfWithDraw(1))

    val refreshState = result.switchMap { it.refreshing }.map { it == PagedList.LoadState.DONE }

    val loadMoreState = result.switchMap { it.loadingMoreState }.map { it == PagedList.LoadState.DONE }

    val err = result.switchMap { it.err }


    val records = result.switchMap { it.pagedList }

    fun refresh() {
        result.value = detailRepository.recordsOfWithDraw(1)
    }
}
